import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//引入path模块
import { resolve } from "path"
//引入markdown组件
import Markdown from 'vite-plugin-md'

//自动导入组件以及样式
//注意unplugin-auto-import后面是vite
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue({
      include: [/\.vue$/, /\.md$/], // <--
    }),
    Markdown({
      builders: []
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],

  //配置环境变量文件的路径
  envDir: "./src",

  //读取除VITE开头的其他前缀
  envPrefix: ["VITE_", "APP_", "NODE_"],

  //配置别名
  resolve: {
    alias: {
      '@': resolve(__dirname, "src")
    }
  },

  //白屏解决
  // base:"/home"

  //跨域代理设置
  server: {
    port: 8002,
    //允许跨域
    cors: true,
    //遇到api开头的，自动替换为target对应的地址请求
    proxy: {
      '/api': {  //注意：这里的api要和request.ts中的baseURL保持一致
        target: "http://xxxx.com",
        changeOrigin: true
      }
    }

  },

})
